function anagram(str1, str2) {  
    if (str1.length !== str2.length) {  
      return false;  
    }  
    const charCount = {};  
    for (let i = 0; i < str1.length; i++) {  
      const char = str1[i];  
      const count = charCount[char] || 0;  
      charCount[char] = count + 1;  
    }  
    for (let i = 0; i < str2.length; i++) {  
      const char = str2[i];  
      if (!charCount[char]) {  
        return false;  
      }  
      const count = charCount[char] || 0;  
      charCount[char] = count - 1;  
    }  
    return true;  
  }

module.exports = anagram;